﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Configuration;
using System.Net;
using System.IO;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;

namespace DMS.Business.WebControls
{
    [ToolboxData("<{0}:StreamImage runat=server></{0}:StreamImage>")]
    public class StreamImage : System.Web.UI.WebControls.Image
    {
        private string _StreamHandler = "/Common/Services/GetMaterialPhoto.aspx";
        public string StreamHandler
        {
            get
            {
                return this._StreamHandler;
            }
            set
            {
                this._StreamHandler = value;
            }
        }
        public string OriginalUrl
        {
            get
            {
                if (this.ViewState["OriginalUrl"] == null)
                {
                    return string.Empty;
                }
                return this.ViewState["OriginalUrl"].ToString();
            }
            private set
            {
                this.ViewState["OriginalUrl"] = value;
            }
        }
        private bool _IsReadFromStream = true;
        public bool IsReadFromStream
        {
            get
            {
                return this._IsReadFromStream;
            }
            set
            {
                this._IsReadFromStream = value;
            }
        }
        public override string ImageUrl
        {
            get
            {
                return base.ImageUrl;
            }
            set
            {
                if (this._IsReadFromStream)
                {
                    this.OriginalUrl = value;
                    base.ImageUrl = string.Format("{0}?Image={1}", this._StreamHandler, value);
                }
                else
                {
                    base.ImageUrl = value;
                }
            }
        }
    }
}
